<template>
  <div>
    <ky-table
      :getData="getConfigList"
      :search_data="search_data"
      :search_criteria="search_criteria"
    >
      <template v-slot:table>
         <el-table-column type="expand">
            <template slot-scope="scope">
              <el-form label-position="left" inline>
                <el-form-item :label="$t('description')">
                  <span>{{ scope.row.description }}</span>
                </el-form-item>
              </el-form>
            </template>
          </el-table-column>
        <el-table-column prop="name" :label="$t('configure.configure_name')">
        </el-table-column>
        <el-table-column
          prop="configType"
          :label="$t('configure.configure_type')"
        >
        </el-table-column>
        <el-table-column prop="attribute" :label="$t('attribute')">
        </el-table-column>
        <el-table-column prop="baseline" :label="$t('configure.configure_value')">
        </el-table-column>
        <el-table-column prop="flag" :label="$t('configure.restart_sign')">
        </el-table-column>
        <el-table-column prop="filePath" :label="$t('configure.file_path')">
        </el-table-column>
      </template>
    </ky-table>
  </div>
</template>

<script>
import kyTable from "@/components/KyTable";
import {getConfigList} from "@/api/host_detail";
import {getClassInfo} from "@/api/config";
export default {
  components: {
    kyTable,
  },
  data() {
    return {
      search_data: {
          name: {
              name: "configure.configure_name",
              type: "text"
          },
          configType: {
              name: "configure.configure_type",
              type: "select",
              items: [],
              func: this.getConfigureInfo
          },
          attribute: {
              name: "attribute",
              type: "select",
              items: []
          },
          baseline: {
              name: "configure.configure_value",
              type: "text"
          },
          flag: {
              name: "configure.restart_sign",
              type: "select",
              items: [
                  {key: true, name: this.$t("true")},
                  {key: false, name: this.$t("false")},
              ]
          },
          filePath: {
              name: "configure.file_path",
              type: "select",
              items: []
          }
      },
      search_criteria: {
          hostId: this.$route.params.id
      }
    };
  },
  methods: {
      getConfigList,
      getConfigureInfo() {
          getClassInfo().then(res => {
              let data = res.data.data;
              let configTypes = Object.keys(data);
              let files = [];
              let attrs = [];
              configTypes.forEach(key => {
                  this.search_data["configType"].items.push({key, name: key});
                  data[key].forEach(item => {
                      for (let k in item) {
                          const attrIndex = attrs.indexOf(k);
                          if (attrIndex < 0) {
                              attrs.push(k);
                              this.search_data["attribute"].items.push({key: k, name: k})
                          }
                          const index = files.indexOf(item[k]);
                          if (index < 0) {
                              files.push(item[k]);
                              this.search_data["filePath"].items.push({key: item[k], name: item[k]})
                          }
                      }
                  })
              })
          })
      }
  }
};
</script>

<style>
</style>